home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / lib / adm / dilate_xpm_files < prev    next >
Text File  |  1996-07-24  |  3KB  |  82 lines

  1. #!/usr/local/bin/perl
  2. # -*- Perl -*-
  3. # usage: dilate [-t<number>] file1 [..filen]
  4. # filenames are colored crossfire xpm-files.
  5. # -t option sets the minimum amount of pixels around needed to set the pixel.
  6. #    default is 1.
  7.  
  8. @dirx = ( 0, 1, 1, 1, 0, -1, -1, -1);
  9. @diry = ( -1, -1, 0, 1, 1, 1, 0, -1);
  10.  
  11. $th = 1;
  12. if ($ARGV[0] =~ /-t(.*)/) {    
  13.     shift;    
  14.     $th = $1 ? $1 : shift;
  15. }
  16.  
  17. print "$th\n";
  18.  
  19. while ($face = shift) {
  20.     print ">$face<\n";
  21.     open (FA, "<$face") || warn "aargh";
  22.     open (OR, ">pah") || die "aargh";
  23.     $changed = 0;
  24.     @m = ();
  25.     while ($_ = <FA>) {
  26.         if (/"(\d+)\s+(\d+)\s+(\d+)\s+(\d+)"/) {
  27.             $cols = $3 + 1;
  28.             print OR "\"$1 $2 $cols $4\",\n";
  29.             next;
  30.         }
  31.         if (/\/\*\s*colors\s*\*\//) {
  32.             print OR "/* colors */\n";
  33.             print OR "\"       s None  c None\",\n";
  34.             $count = 0;
  35.             while (($_ = <FA>) && /"(.) (.) (.*)",/) {
  36.                 print "$1 $2 $3\n";
  37.                 $colors[$count++] = $1;
  38.                 print OR $_;
  39.             }
  40.         }
  41.         if (/\/\*\s*pixels\s*\*\//) {
  42.             print OR "/* pixels */\n";
  43.             $count = 0;
  44.             while (($_ = <FA>) && /"(........................)"(.*)/) { 
  45.                 $save[$count] = $2;
  46.                 print "$1, ***$save[$count]***\n";
  47.                 $arr[$count++] = $1;
  48.                 push (@m, split ('', $1));
  49.                 last if ($2 ne ",");
  50.             }
  51.             die "illegal count $count" if ($count != 24);
  52.             foreach $y (0..23) {
  53.                 $row = "";
  54.                 foreach $x (0..23) {                
  55.                     if ($m[$x + $y * 24] eq $colors[0]) {
  56.                         $row .= $colors[0];
  57.                         next;
  58.                     }
  59.                     $sum = 0;
  60.                     foreach $i (0..7) {
  61.                         $nx = $x + $dirx[$i];
  62.                         $ny = $y + $diry[$i];
  63.                         $sum++ if ($nx >= 0 && $nx < 24 && $ny >= 0 && $ny < 24 &&
  64.                                    $m[$nx + $ny * 24] eq $colors[0]);
  65.                     }
  66.                     #print "$x $y $sum\n";
  67.                     $row .= ($sum >= $th) ? $colors[1] : " ";
  68.                 }
  69.                 print ">$row<\n";
  70.                 print OR "\"$row\"$save[$y]\n";
  71.             }
  72.             next;
  73.         }
  74.         print OR $_;
  75.     }
  76.     close (FA);
  77.     close (OR);
  78.     unlink ("$face");
  79.     rename ("pah", "$face") || die "rename";
  80. }
  81.